Skip to content

Conversation

@ela-kotulska-frequenz
Copy link
Contributor

Actor should be able to restart _run method
For example to update formula and start listening on new receiver.
Restarting actor should not print exception.

@ela-kotulska-frequenz ela-kotulska-frequenz added the part:actor Affects an actor ot the actors utilities (decorator, etc.) label Feb 27, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz self-assigned this Feb 27, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz requested a review from a team as a code owner February 27, 2025 11:43
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Feb 27, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz marked this pull request as draft February 27, 2025 11:49
@ela-kotulska-frequenz ela-kotulska-frequenz removed request for a team, llucax and shsms February 27, 2025 11:49
Actor should be able to restart `_run` method
for example to update formula and start listening on new receiver.
Restarting actor should not print exception.

Signed-off-by: Elzbieta Kotulska <[email protected]>
Because this nane is more descriptive.

Signed-off-by: Elzbieta Kotulska <[email protected]>
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand where this comes from, but I'm not sure if it is the path we want to follow in the future (#632).

That said, this is how things work now and I can see how having a convenient way to restart is helpful, but an exception is also not the only way to restart, and have some implications. Mainly, anyone, at any level in the call stack, can trigger an actor restart.

An alternative that can prevent this, would be to use a asyncio.Event and await the event or the actor to finish, and then restart it if we got the event. Then adding the Actor class a restart() method that just triggers the event.

Even when Python already uses this exception mechanism for exits (like SystemExit or GeneratorExit), I'm not sure this is the right approach, because in those cases they are BaseExceptions and nobody is supposed to catch them (and body will, unless they explicitly catch BaseException),but with RestartActorException, it shouldn't inherit from BaseException (as per Python docs), but if it doesn't, it also mean anyone using except Exception, will probably avoid restarting the actor (unwillingly), so it has its risks.

All that said, since restarting actors like this should probably change in the future, I'm not sure how important is to get this perfectly right, but unless we really need the exception, I think it would be safer to go for a restart() method with an event.

Args:
iteration: The current iteration of the restart.
"""
async def _delay(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it a bit more explicit?

Suggested change
async def _delay(self) -> None:
async def _delay_restart(self) -> None:

@ela-kotulska-frequenz
Copy link
Contributor Author

Closed, to discuss later how we should implement it

@github-project-automation github-project-automation bot moved this from To do to Done in Python SDK Roadmap Apr 7, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz deleted the restart_actor branch June 11, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:actor Affects an actor ot the actors utilities (decorator, etc.) part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

Development

Successfully merging this pull request may close these issues.

2 participants